Page({
  data: {
    payType: ""
  },
  onLoad: function(options) {
    var that = this;
    //页面加载调取微信支付（原则上应该对options的携带的参数进行校验）
    that.requestPayment(options);
    this.setData({
      payType: options.payType
    })
  },
  requestPayment: function(obj) {
    let that = this;
    //调起微信支付
    wx.requestPayment({
      //相关支付参数
      'timeStamp': obj.timeStamp,
      'nonceStr': obj.nonceStr,
      'package': `prepay_id=${obj.package}`,
      'paySign': obj.paySign,
      'signType': 'MD5',

      success(res) {
        //小程序微信支付成功的回调通知
        console.log("支付成功");
        wx.redirectTo({
          url: `../index/index?payType=${that.data.payType}`
        })
      },
      fail(res) {
        //小程序支付失败的回调通知
        console.log("支付失败");
        wx.navigateBack({
          delta: '1'
        })

      }
    })
  },

})